const express = require('express');
const router = express.Router();

router.ws('/test', (ws, req) => {
	ws.on('message', (msg) => {
		ws.send(msg);
	});

	ws.on('close', () => {
		console.log('close');
	});

	ws.on('error', () => {
		console.log('error');
	});

	ws.on('open', () => {
		console.log('open');
	});

	ws.on('ping', () => {
		console.log('ping');
	});

	ws.on('pong', () => {
		console.log('pong');
	});

	ws.on('unexpected-response', () => {
		console.log('unexpected-response');
	});

	ws.on('upgrade', () => {
		console.log('upgrade');
	});
});

// 挂接
const Router = (app) => {
	app.use('/ws', router);
};

module.exports = { Router };
